<template>
  <li>
    <span :class="{ completed: todo.completed }" @click="toggleCompleted">
      {{ todo.text }}
    </span>
    <button @click="removeTodo">删除</button>
  </li>
</template>

<script lang="ts">
import { defineComponent, type PropType } from 'vue';

interface Todo {
  text: string;
  completed: boolean;
}

export default defineComponent({
  name: 'TodoItem',
  props: {
    todo: {
      type: Object as PropType<Todo>,
      required: true
    },
    index: {
      type: Number,
      required: true
    }
  },
  emits: ['toggle-completed', 'remove-todo'],
  setup(props, { emit }) {
    const toggleCompleted = () => {
      emit('toggle-completed', props.index);
    };

    const removeTodo = () => {
      emit('remove-todo', props.index);
    };

    return { toggleCompleted, removeTodo };
  }
});
</script>

<style scoped>
li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  margin-bottom: 10px;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

li span {
  flex-grow: 1;
  cursor: pointer;
}

.completed {
  text-decoration: line-through;
  color: #888;
}

button {
  background-color: #f44336;
}

button:hover {
  background-color: #e53935;
}
</style>